﻿<%@ Page Title="Simple Embeddable Wiki Engine" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ContentPlaceHolderID="MainCPH" runat="Server">
    <asp:FormView ID="PageFormView" runat="server" DataSourceID="PageObjectDataSource" RenderOuterTable="false" OnItemInserted="PageFormView_ItemInserted">
        <EmptyDataTemplate>
            <h1 class="title">Page not found</h1>
            <div class="body">
                <p>Specified page was not found.</p>
            </div>
            <div class="buttons">
                <asp:Button runat="server" CausesValidation="False" CommandName="New" Text="New Page" />
            </div>
        </EmptyDataTemplate>
        <ItemTemplate>
            <h1 class="title">
                <asp:Literal runat="server" Text='<%# Eval("Title") %>' />
            </h1>
            <div class="head">
                <asp:Literal runat="server" Text='<%# Eval("Version", "Version: {0:d} {0:T} | ") %>' />
                <asp:Literal runat="server" Text='<%# Eval("UserName", "User: {0} | ") %>' />
                <asp:Literal runat="server" Text='<%# Eval("IpAddress", "IP: {0} | ") %>' />
                <asp:HyperLink runat="server" NavigateUrl='<%# Eval("Slug", "~/History.aspx?page={0}") %>' Text="history" />
                |
                <asp:LinkButton runat="server" CausesValidation="False" CommandName="Edit" Text="edit page" />
                |
                <asp:LinkButton runat="server" CausesValidation="False" CommandName="New" Text="new page" />
                |
                <asp:HyperLink runat="server" NavigateUrl="~/Search.aspx" Text="search" />
            </div>
            <sewen:WikiMarkup runat="server" CssClass="body" Text='<%# Eval("Body") %>' />
        </ItemTemplate>
        <EditItemTemplate>
            <h1 class="title">
                <asp:Literal runat="server" Text="Edit page" />
                <asp:Literal ID="LiteralTitle" runat="server" Text='<%# Bind("Title") %>' />
            </h1>
            <div class="head">
                <asp:Literal runat="server" Text='<%# Eval("Version", "Version: {0:d} {0:T}") %>' />
                <asp:Literal runat="server" Text='<%# Eval("UserName", "| User: {0}") %>' />
                <asp:Literal runat="server" Text='<%# Eval("IpAddress", "| IP: {0}") %>' />
            </div>
            <div class="body">
                <asp:TextBox ID="BodyTextBoxHtml" runat="server" Text='<%# Bind("Body") %>' TextMode="MultiLine" Height="400px" />
                <p>
                    <asp:Label runat="server" Text="Comment:" AssociatedControlID="CommentTextBox" />
                    <br />
                    <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' />
                </p>
            </div>
            <div class="buttons">
                <asp:RequiredFieldValidator runat="server" ControlToValidate="BodyTextBoxHtml" ErrorMessage="Body is missing" Display="None" />
                <asp:ValidationSummary runat="server" />
                <asp:Button runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                <asp:Button runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </div>
        </EditItemTemplate>
        <InsertItemTemplate>
            <h1 class="title">Create new page</h1>
            <div class="body">
                <p>
                    <asp:Label runat="server" Text="Title:" AssociatedControlID="TitleTextBox" />
                    <br />
                    <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
                </p>
                <p>
                    <asp:Label runat="server" Text="Body:" AssociatedControlID="BodyTextBoxHtml" />
                    <br />
                    <asp:TextBox ID="BodyTextBoxHtml" runat="server" Text='<%# Bind("Body") %>' TextMode="MultiLine" Height="300px" />
                </p>
            </div>
            <div class="buttons">
                <asp:RequiredFieldValidator runat="server" ControlToValidate="TitleTextBox" ErrorMessage="Title is missing" Display="None" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="BodyTextBoxHtml" ErrorMessage="Body is missing" Display="None" />
                <asp:ValidationSummary runat="server" />
                <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                <asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </div>
        </InsertItemTemplate>
    </asp:FormView>
    <asp:ObjectDataSource ID="PageObjectDataSource" runat="server" TypeName="Altairis.Sewen.PageStoreManager" DataObjectTypeName="Altairis.Sewen.SewenPage" SelectMethod="LoadPage" InsertMethod="SavePage" UpdateMethod="SavePage">
        <SelectParameters>
            <asp:QueryStringParameter Name="name" QueryStringField="page" Type="String" DefaultValue="home-page" />
            <asp:QueryStringParameter Name="versionString" QueryStringField="version" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>
